<!--
 * @Author: yudj
 * @Date: 2020-07-15 16:57:07
 * @LastEditTime: 2020-07-30 10:44:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \yudianjiangtest\src\views\Home\index.vue
--> 
<template>
  <el-form class="form-style"
           ref="form"
           :model="form"
           label-width="80px">
    <el-form-item label="账号">
      <el-input placeholder="请输入账号" v-model="form.username"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input placeholder="请输入密码" v-model="form.password" show-password></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary"
                 @click="onSubmit">登陆</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import baseUrl from "./../common/js/env.js";
import http from "./../common/js/http.js";
export default {
  components: {
  },
  data () {
    return {
      form: {
        username: '',
        password: '',
      }
    }
  },
  
  methods: {
    onSubmit () {
      console.log(this.$store.state)
      let payload = {};
      console.log(Object.keys(this.form));
      Object.keys(this.form).forEach(key => {
        if (this.form[key]) {
          payload[key] = this.form[key];
        }
      });
      let username = payload.username
      this.$store.dispatch("login", payload).then(data => {
        if (data == null) {
          this.loginTimesS();
        } else {
          let aa = sessionStorage.getItem(JSON.parse(username)) //返回键名(key)对应的值(value)。若没有返回null。
          console.log(aa)
          this.$router.push({ path:'/HomePage'})//跳转页面
          return false;
          this.getinfo();
          window.sessionStorage.setItem("token", data.token);
          window.setTimeout(() => {
            window.localStorage.setItem("LOGINTIMES", 0);
            this.$router.push({
              path: this.routerPath
            });
          }, 1000);
        }
      });
    }
  },
  //   created() {
  //     this.$api.post('erp/login', {
  //         "username": "123",
  //         "password": "321",
  //     }, response => {
  //          if (response.status >= 200 && response.status < 300) {
  //             console.log(response.data);//请求成功，response为成功信息参数
  //          } else {
  //             console.log(response.message);//请求失败，response为失败信息
  //          }
  //     });
  // }
}

// export default {

// }
</script>
